package co.chuangdian.oflauncher.setting;

import co.chuangdian.oflauncher.OFActivity;
import co.chuangdian.oflauncher.R;
import org.json.JSONObject;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Switch;
import cn.onekit.CONFIG;
import cn.onekit.JSON;
import cn.onekit.android.ACTIVITY;

public class HomeActivity extends OFActivity implements OnClickListener {
	CheckBox defaultDesktopSwitch;
	JSONObject setting;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setting);
		//
		this.findViewById(R.id.guestureRow).setOnClickListener(this);
		this.findViewById(R.id.unlockScreenRow).setOnClickListener(this);
		this.findViewById(R.id.lockScreenRow).setOnClickListener(this);
		this.findViewById(R.id.updateRow).setOnClickListener(this);
		this.findViewById(R.id.aboutRow).setOnClickListener(this);
		this.findViewById(R.id.feedbackRow).setOnClickListener(this);
		//
		defaultDesktopSwitch = (CheckBox) this.findViewById(R.id.defaultDesktopSwitch);
		defaultDesktopSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				// try {
				// setting.put("default_desktop", isChecked);
				// CONFIG.set("setting", setting);
				// } catch (JSONException e) {
				// e.printStackTrace();
				// }
				try {
					Intent intent = new Intent(Intent.ACTION_MAIN);
					intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);// 注意
					intent.addCategory(Intent.CATEGORY_HOME);
					startActivity(intent);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

		});
		///////////////////
		String settingString = (String) CONFIG.get("setting");
		setting = JSON.parse(settingString);
		//
		// boolean default_desktop = setting.optBoolean("default_desktop");
		// defaultDesktopSwitch.setChecked(default_desktop);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.guestureRow:
			startActivity(new Intent(this, GesturesActivity.class));
			break;
		case R.id.unlockScreenRow:
			startActivity(new Intent(this, UnlockScreenActivity.class));
			break;
		case R.id.lockScreenRow:
			startActivity(new Intent(this, LockScreenActivity.class));
			break;
		case R.id.updateRow:
			startActivity(new Intent(this, UpdatePageActivity.class));
			break;
		case R.id.aboutRow:
			startActivity(new Intent(this, AboutActivity.class));
			break;
		case R.id.feedbackRow:
			startActivity(new Intent(this, FeedbackActivity.class));
			break;
		default:
			break;
		}

	}

}
